package com.pri.chat.nim.session.viewholder;

import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.netease.nim.uikit.business.session.viewholder.MsgViewHolderBase;
import com.netease.nim.uikit.common.ui.recyclerview.adapter.BaseMultiItemFetchLoadAdapter;
import com.netease.nim.uikit.net.SharedHelper;
import com.pri.chat.R;
import com.pri.chat.nim.session.extension.GiftAttachment;

/**
 * 类描述：
 *
 * @author mhd
 */
public class MsgViewHolderGift extends MsgViewHolderBase {

    private View otherLinear;
    private ImageView ivGift;
    private TextView tvDescribe;

    private View meLinear;
    private ImageView ivGift1;
    private TextView tvDescribe1;

    public MsgViewHolderGift(BaseMultiItemFetchLoadAdapter adapter) {
        super(adapter);
    }

    @Override
    public int getContentResId() {
        return R.layout.item_message_gift;
    }

    @Override
    public void inflateContentView() {
        otherLinear = findViewById(R.id.otherLinear);
        ivGift = findViewById(R.id.iv_gift);
        tvDescribe = findViewById(R.id.tv_describe);

        meLinear = findViewById(R.id.meLinear);
        ivGift1 = findViewById(R.id.iv_gift1);
        tvDescribe1 = findViewById(R.id.tv_describe1);


    }

    private static final String TAG = "MsgViewHolderGift";
    @Override
    public void bindContentView() {
        GiftAttachment  attachment = (GiftAttachment) message.getAttachment();
        Log.d(TAG, "inflateContentView: "+attachment.getImageUrl());
        String imageUrl = attachment.getImageUrl();
        String describe = attachment.getDescribe();
        int money = attachment.getMoney();

        Glide.with(context).load(imageUrl).error(com.netease.nim.uikit.R.drawable.nim_default_img_failed).into(ivGift);


        Glide.with(context).load(imageUrl).error(com.netease.nim.uikit.R.drawable.nim_default_img_failed).into(ivGift1);
        tvDescribe1.setText(describe);
        if(SharedHelper.readId(context).equals(message.getFromAccount())){
            meLinear.setVisibility(View.VISIBLE);
            otherLinear.setVisibility(View.GONE);
            tvDescribe1.setText("打赏"+describe+":-"+money+"金币");
        }else{
            meLinear.setVisibility(View.GONE);
            otherLinear.setVisibility(View.VISIBLE);
            tvDescribe.setText("收到"+describe+":+"+(money/2)+"金币");
        }
    }

    @Override
    protected boolean isShowBubble() {
        return false;
    }

}
